/**
 * 
 */
package il.ac.braude.sona.control;

import il.ac.braude.sona.constants.Mssg;
import il.ac.braude.sona.constants.P;
import il.ac.braude.sona.constants.Resources;
import il.ac.braude.sona.entities.SupervisorAction;
import il.ac.braude.sona.gui.list_table.ListTableModel;
import il.ac.braude.sona.gui.mytables.SuperActionsTableFrame;
import il.ac.braude.sona.ocsf.client.Client;
import il.ac.braude.sona.ocsf.client.ServerResponseListener;

import java.awt.Dimension;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.JOptionPane;

/**
 * The SupervisorActionController conatins methods to view supervisor actions
 * 
 * @author Ofek Ron
 * @author Avihay Avitan
 * @author Nitzan Inbar
 * @author Sasha Rozenthal
 *
 */
public class SupervisorActionController 
{
	/**
	 * Execute view of all supervisor actions
	 */
	public void execViewSupervisorActions()
	{
		try {
 
			Mssg msg = new Mssg(P.SupAction);
			final SuperActionsTableFrame tableFrame = new SuperActionsTableFrame();
			Client.getInstance().sendToServer(new ServerResponseListener() {
				@SuppressWarnings("unchecked")
				@Override
				public void onServerResponse(Mssg mssg) {
					if (mssg.is(P.error)) {
						JOptionPane.showMessageDialog(null,
								(mssg.getMessege()));
						return;
					}
					ArrayList<SupervisorAction> n = (ArrayList<SupervisorAction>)mssg.getMessege();
					tableFrame.getContentPane().removeAll();
					ListTableModel<SupervisorAction> model =new ListTableModel<SupervisorAction>(n);
					tableFrame.setTable(model);
					tableFrame.setPreferredSize(new Dimension(575,600));
					tableFrame.setResizable(false);
					tableFrame.showFrame();
				}
			}, msg);

		} catch (IOException e) {
			JOptionPane
					.showMessageDialog(null, Resources.Strings.ConnectFailed);
		}
	}
}
